﻿#建议保存编码为：bom头 + utf8
param
(
	[parameter(Mandatory = $true)]
	[ValidateNotNullOrEmpty()]
	[Alias("cname")][String]$cluster名
)

& "${PSScriptRoot}/check_cds.ps1" $cluster名
if ($LASTEXITCODE -eq 1)
{
	& "${PSScriptRoot}/Write-Error2.ps1"  '错误：cluster名字不合法。退出码1'
	exit 1
}

if ($LASTEXITCODE -eq 2)
{
	& "${PSScriptRoot}/Write-Error2.ps1"  "错误：不存在${cluster名}文件夹。退出码2"
	exit 2
}


& "${PSScriptRoot}/_bak_cds.ps1"

Remove-Item -Recurse -Force -LiteralPath "${PSScriptRoot}/${cluster名}"

#更新cds.json
$private:cds = Get-Content -LiteralPath "${PSScriptRoot}/cds.json" | ConvertFrom-Json -Depth 99
$temp002 = @()
foreach ($temp001 in $private:cds.resources)
{
	if ($temp001.name -eq ${cluster名})
	{
		continue
	}
	else
	{
		$temp002 += $temp001
	}
}
$private:cds.resources = $temp002
$private:cds2 = $private:cds | ConvertTo-Json -Depth 99
Set-Content -LiteralPath "${PSScriptRoot}/cds.json" -Value $private:cds2 -Encoding utf8NoBOM

& "${PSScriptRoot}/_flashfile.ps1" "${PSScriptRoot}/cds.json"
& "${PSScriptRoot}/Write-Host2.ps1"  -ForegroundColor Green '信息：删除cluster成功'
exit 0
